<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>商品管理</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <link rel="stylesheet" href="/plugins/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="/plugins/adminLTE/css/AdminLTE.css">
    <link rel="stylesheet" href="/plugins/adminLTE/css/skins/_all-skins.min.css">
    <link rel="stylesheet" href="/css/style.css">
    <script src="/plugins/jQuery/jquery-2.2.3.min.js"></script>
    <script src="/plugins/bootstrap/js/bootstrap.min.js"></script>
</head>

<body class="hold-transition skin-red sidebar-mini">
<!-- .box-body -->
<div class="box-header with-border">
    <h3 class="box-title">商品审核</h3>
</div>
<div class="box-body">
    <!-- 数据表格 -->
    <div class="table-box">
        <!--工具栏-->
        <div class="pull-left">
            <div class="form-group form-inline">
                <div class="btn-group">
                    <button type="button" onclick="deleteallTbGoods()" class="btn btn-default" title="批量删除"><i
                            class="fa fa-trash-o"></i> 批量删除
                    </button>
                    <button type="button" onclick="updateallTbGoodsbya()" class="btn btn-default" title="审核通过"><i
                            class="fa fa-check"></i> 审核通过
                    </button>
                    <button type="button" onclick="updateallTbGoodsbyb()" class="btn btn-default" title="驳回"><i
                            class="fa fa-ban"></i> 驳回
                    </button>
                    <button type="button" onclick="window.location.reload();" class="btn btn-default" title="刷新"><i
                            class="fa fa-refresh"></i> 刷新
                    </button>
                </div>
            </div>
        </div>
        <div class="box-tools pull-right">
            <div class="has-feedback">
                商品名称：<input id="goodsName">
                <button onclick="onreload()" class="btn btn-default">查询</button>
            </div>
        </div>
        <!--工具栏/-->
        <!--数据列表-->
        <table id="dataList" class="table table-bordered table-striped table-hover dataTable">
            <thead>
            <tr>
                <th class="" style="padding-right:0px">
                    <input id="selall" type="checkbox" onclick="reversal()" class="icheckbox_square-blue">
                </th>
                <th class="sorting_asc">商品ID</th>
                <th class="sorting">商品名称</th>
                <th class="sorting">商品价格</th>
                <th class="sorting">一级分类</th>
                <th class="sorting">二级分类</th>
                <th class="sorting">三级分类</th>
                <th class="sorting">状态</th>
                <th class="text-center">操作</th>
            </tr>
            </thead>
            <tbody id="goodsshuju">
            </tbody>
        </table>
        <!--数据列表/-->
    </div>
    <!-- 数据表格 /-->
</div>
<!-- /.box-body -->
<!--复选框反转-->
<script type="text/javascript">

    //页面加载事件
    $(function () {
        onreload()
    })

    //加载商品数据
    function onreload() {
        var goodsName = $("#goodsName").val();
        let pageNum = $("#pageNum").text();
        let pages = $("#pages").text();
        $.ajax({
            url: "/TbGoods/TbGoodsshowall",
            data: {pageNum: pageNum, pages: pages, goodsName: goodsName},
            type: "post",
            dataType: "json",
            async: false,
            success: function (pm) {
                var rows = pm.data.rows;
                var s = '';
                $(rows).each(function (i, e) {
                    var auditStatus;
                    if (e.auditStatus == 0) {
                        auditStatus = "未审核"
                    } else if (e.auditStatus == 1) {
                        auditStatus = "审核通过"
                    } else if (e.auditStatus == 2) {
                        auditStatus = "审核未通过"
                    }
                    s += '<tr>'
                    s += '<td><input type="checkbox" name="checkbox" value="' + e.id + '"></td>'
                    s += '<td>' + e.id + '</td>'
                    s += '<td>' + e.goodsName + '</td>'
                    s += '<td>' + e.price + '</td>'
                    s += '<td>' + e.category1 + '</td>'
                    s += '<td>' + e.category2 + '</td>'
                    s += '<td>' + e.category3 + '</td>'
                    s += '<td><span>' + auditStatus + '</span></td>'
                    s += '<td className="text-center">'
                    s += '<!--<button type="button" class="btn bg-olive btn-xs">详情</button>-->'
                    s += '<button type="button" onclick="deleteTbGoods(' + e.id + ')" className="btn bg-olive btn-xs">删除</button>'
                    s += '</td>'
                    s += '</tr>'
                })
                s += '<tr><td colspan="7">'
                s += '<input type="button" value="首页" onclick="skip(0)"> '
                s += '<input type="button" value="上一页" onclick="skip(1)"> '
                s += '<span id="pageNum">' + pm.data.pageNum + '</span> / <span id="pages">' + pm.data.pages
                s += '</span> <input type="button" value="下一页" onclick="skip(2)"> '
                s += '<input type="button" value="末页" onclick="skip(3)"> '
                s += '</td></tr>'
                $("#goodsshuju").html(s)
            },
            error: function () {
                alert("系统异常")
            }
        })
    }

    //全选事件
    function reversal() {
        $("[name=checkbox]").prop("checked", $("#selall").prop("checked"))
    }

    //换页逻辑
    function skip(pm) {
        let pageNum = $("#pageNum").text();
        let pages = $("#pages").text();
        if (pm == 0) {
            if (pageNum == 1) {
                alert("已是首页")
            } else {
                $("#pageNum").text(1)
                onreload()
            }
        } else if (pm == 1) {
            if (pageNum == 1) {
                alert("已是第一页")
            } else {
                $("#pageNum").text(pageNum - 1)
                onreload()
            }
        } else if (pm == 2) {
            if (pageNum == pages) {
                alert("已是最后一页")
            } else {
                $("#pageNum").text(parseInt(pageNum) + 1)
                onreload()
            }
        } else if (pm == 3) {
            if (pageNum == pages) {
                alert("已是末页")
            } else {
                $("#pageNum").text(pages)
                onreload()
            }
        }
    }

    //删除单个数据
    function deleteTbGoods(id) {
        if (confirm("你确定要删除吗?")) {
            $.ajax({
                url: "/TbGoods/deleteTbGoods",
                data: {id: id},
                type: "post",
                dataType: "json",
                async: false,
                success: function (pm) {
                    alert(pm.message)
                    onreload()
                },
                error: function () {
                    alert("系统异常")
                }
            })
        }
    }

    //多条数据删除
    function deleteallTbGoods() {
        var ids = []
        $("[name=checkbox]").each(function (i, e) {
            if ($(e).prop("checked")) {
                ids.push($(e).val())
            }
        })
        if (ids == '') {
            alert("请先选择要删除的数据")
            return
        }
        if (confirm("你确定要删除吗?")) {
            $.ajax({
                url: "/TbGoods/deleteallTbGoods",
                data: {ids: ids},
                type: "post",
                dataType: "json",
                async: false,
                success: function (pm) {
                    alert(pm.message)
                    onreload()
                },
                error: function () {
                    alert("系统异常")
                }
            })
        }
    }

    //审核通过
    function updateallTbGoodsbya() {
        var ids = []
        $("[name=checkbox]").each(function (i, e) {
            if ($(e).prop("checked")) {
                ids.push($(e).val())
            }
        })
        if (ids == '') {
            alert("请先选择要审核的数据")
            return
        }
        $.ajax({
            url: "/TbGoods/updateallTbGoodsbya",
            data: {ids: ids},
            type: "post",
            dataType: "json",
            async: false,
            success: function (pm) {
                alert(pm.message)
                onreload()
            },
            error: function () {
                alert("系统异常")
            }
        })
    }

    //审核驳回
    function updateallTbGoodsbyb() {
        var ids = []
        $("[name=checkbox]").each(function (i, e) {
            if ($(e).prop("checked")) {
                ids.push($(e).val())
            }
        })
        if (ids == '') {
            alert("请先选择要驳回的数据")
            return
        }
        $.ajax({
            url: "/TbGoods/updateallTbGoodsbyb",
            data: {ids: ids},
            type: "post",
            dataType: "json",
            async: false,
            success: function (pm) {
                alert(pm.message)
                onreload()
            },
            error: function () {
                alert("系统异常")
            }
        })
    }
</script>
</body>
</html>